/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.portlet.editor.gui.view.internal;

import com.genia.toolbox.basics.editor.gui.view.internal.AbstractViewFactory;
import com.genia.toolbox.basics.editor.gui.view.internal.panel.ElementViewPanel;
import com.genia.toolbox.portlet.editor.gui.PortletEditorGUI;
import com.genia.toolbox.portlet.editor.gui.view.internal.panel.ContainerPortletViewPanel;
import com.genia.toolbox.portlet.editor.gui.view.internal.panel.DispatchedPortletViewPanel;
import com.genia.toolbox.portlet.editor.gui.view.internal.panel.HolePortletViewPanel;
import com.genia.toolbox.portlet.editor.gui.view.internal.panel.LinkedPortletViewPanel;
import com.genia.toolbox.portlet.editor.gui.view.internal.panel.SimplePortletViewPanel;
import com.genia.toolbox.portlet.editor.gui.view.internal.panel.TemplatePortletViewPanel;
import com.genia.toolbox.portlet.editor.model.document.impl.DocumentModel;
import com.genia.toolbox.portlet.editor.model.portlet.PortletType;
import com.genia.toolbox.portlet.editor.model.portlet.impl.ContainerPortletModel;
import com.genia.toolbox.portlet.editor.model.portlet.impl.DispatcherPortletModel;
import com.genia.toolbox.portlet.editor.model.portlet.impl.HolePortletModel;
import com.genia.toolbox.portlet.editor.model.portlet.impl.LinkedPortletModel;
import com.genia.toolbox.portlet.editor.model.portlet.impl.PortletModel;
import com.genia.toolbox.portlet.editor.model.portlet.impl.SimplePortletModel;
import com.genia.toolbox.portlet.editor.model.portlet.impl.TemplatePortletModel;

/**
 * View factory, create the view according to the portlet.
 */
public class PortletViewFactory
    extends AbstractViewFactory<PortletEditorGUI, PortletDocumentInternalFrame, DocumentModel, PortletModel>
{

  /**
   * Constructor.
   * 
   * @param portletEditorGUI
   *          the portletEditorGUI.
   * @param internalFrame
   *          the internal frame.
   */
  public PortletViewFactory(PortletEditorGUI portletEditorGUI, PortletDocumentInternalFrame internalFrame)
  {
    super(portletEditorGUI, internalFrame);
  }



  /**
   * Create a view.
   * 
   * @param model
   *          the portlet model.
   * @return the view.
   */
  @Override
  public ElementViewPanel<PortletEditorGUI, PortletDocumentInternalFrame, PortletModel, PortletType> createView(PortletModel model)
  {
    ElementViewPanel<PortletEditorGUI, PortletDocumentInternalFrame, PortletModel, PortletType> panel = null;
    PortletDocumentInternalFrame internalFrame = this.getInternalFrame();
    if (PortletType.Container.equals(model.getType())) {
      return this.createContainerView((ContainerPortletModel) model, internalFrame);
    }
    else if (PortletType.Simple.equals(model.getType())) {
      return this.createSimpleView((SimplePortletModel) model, internalFrame);
    }
    else if (PortletType.Dispatcher.equals(model.getType())) {
      return this.createDispatchedView((DispatcherPortletModel) model, internalFrame);
    }
    else if (PortletType.Template.equals(model.getType())) {
      return this.createTemplateView((TemplatePortletModel) model, internalFrame);
    }
    else if (PortletType.Hole.equals(model.getType())) {
      return this.createHoleView((HolePortletModel) model, internalFrame);
    }
    else if (PortletType.Linked.equals(model.getType())) {
      return this.createLinkedView((LinkedPortletModel) model, internalFrame);
    }
    return panel;
  }



  /**
   * Create the container view.
   * 
   * @param model
   *          the portlet model.
   * @param internalFrame
   *          the internal frame.
   * @return the container view.
   */
  public ContainerPortletViewPanel createContainerView(ContainerPortletModel model, PortletDocumentInternalFrame internalFrame)
  {
    ContainerPortletViewPanel panel = new ContainerPortletViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the linked view.
   * 
   * @param model
   *          the portlet model.
   * @param internalFrame
   *          the internal frame.
   * @return the linked view.
   */
  public LinkedPortletViewPanel createLinkedView(LinkedPortletModel model, PortletDocumentInternalFrame internalFrame)
  {
    LinkedPortletViewPanel panel = new LinkedPortletViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the dispatched view.
   * 
   * @param model
   *          the portlet model.
   * @param internalFrame
   *          the internal frame.
   * @return the dispatched view.
   */
  public DispatchedPortletViewPanel createDispatchedView(DispatcherPortletModel model, PortletDocumentInternalFrame internalFrame)
  {
    DispatchedPortletViewPanel panel = new DispatchedPortletViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the simple view.
   * 
   * @param model
   *          the portlet model.
   * @param internalFrame
   *          the internal frame.
   * @return the simple view.
   */
  public SimplePortletViewPanel createSimpleView(SimplePortletModel model, PortletDocumentInternalFrame internalFrame)
  {
    SimplePortletViewPanel panel = new SimplePortletViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the hole view.
   * 
   * @param model
   *          the portlet model.
   * @param internalFrame
   *          the internal frame.
   * @return the hole view.
   */
  public HolePortletViewPanel createHoleView(HolePortletModel model, PortletDocumentInternalFrame internalFrame)
  {
    HolePortletViewPanel panel = new HolePortletViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }



  /**
   * Create the template view.
   * 
   * @param model
   *          the portlet model.
   * @param internalFrame
   *          the internal frame.
   * @return the template view.
   */
  public TemplatePortletViewPanel createTemplateView(TemplatePortletModel model, PortletDocumentInternalFrame internalFrame)
  {
    TemplatePortletViewPanel panel = new TemplatePortletViewPanel(this.getGui(), internalFrame);
    panel.initialise();
    panel.setElement(model);
    return panel;
  }

}
